﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GetMsg : MonoBehaviour {
    public Text times, p, wifi;
    public Slider powerNumber;
    public Image surplusPower;
    // Use this for initialization
    void Awake () {
        StartCoroutine("showmsg");
	}

    IEnumerator showmsg() {
        do
        {
            times.text = System.DateTime.Now.ToShortTimeString();
            int number = int.Parse(System.IO.File.ReadAllText("/sys/class/power_supply/battery/capacity"));
            powerNumber.value = number / 100f;
            p.text = number.ToString() + "%";
            if (number < 10) surplusPower.color = new Color(1f, 0, 0, 1);
            else
                surplusPower.color = new Color(62 / 255f, 1, 0, 1);
            if (Application.internetReachability == NetworkReachability.NotReachable)
                wifi.text = "无网络";
            else if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
                wifi.text = "3G/4G";
            else if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
                wifi.text = "WIFI";
            yield return new WaitForSeconds(1);
        } while (true);
    }
}
